home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / ask.sh < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  3.0 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: ken@cs.rochester.edu (Ken Yap)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i047: ask (quick & dirty sh version of K&P pick)
  5. Message-ID: <8811090439.AA11332@elm.cs.rochester.edu>
  6. Date: 10 Nov 88 02:07:50 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: ken@cs.rochester.edu (Ken Yap)
  9. Lines: 109
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 5, Issue 47
  13. Submitted-by: "Ken Yap" <ken@cs.rochester.edu>
  14. Archive-name: ask.sh
  15.  
  16. [Is it legal for someone to type in pick.c and post it?  If so, it may be a
  17. good idea....  ++bsa]
  18.  
  19. In a moment of need I cooked this up in a jiffy. Probably everybody has
  20. written something like this (my friend tells me it's like pick in K+P),
  21. but I couldn't find a similar program on my system.
  22.  
  23. An excerpt from the man page:
  24.  
  25. Ask writes its arguments one at a time on standard error, and prompts
  26. for a reply.  A response beginning with y or Y selects that argument to
  27. be printed to standard output, anything else rejects it.
  28.  
  29. Ask is useful for interactively selecting arguments for a command from
  30. a wildcard specification.
  31.  
  32. #!/bin/sh
  33. # This is a shell archive, meaning:
  34. # 1. Remove everything above the #!/bin/sh line.
  35. # 2. Save the resulting text in a file.
  36. # 3. Execute the file with /bin/sh (not csh) to create the files:
  37. #    ask.1
  38. #    ask.sh
  39. # This archive created: Tue Nov  8 23:31:50 1988
  40. # By:    Ken Yap ()
  41. export PATH; PATH=/bin:$PATH
  42. echo shar: extracting "'ask.1'" '(779 characters)'
  43. if test -f 'ask.1'
  44. then
  45.     echo shar: over-writing existing file "'ask.1'"
  46. fi
  47. cat << \SHAR_EOF > 'ask.1'
  48. .TH ASK 1 "7 November 1988"
  49. .SH NAME
  50. ask \- interactively select arguments
  51. .SH SYNOPSIS
  52. .B ask
  53. [
  54. .B \-s
  55. string ]
  56. .I argument \fB.\|.\|.\fP 
  57. .SH DESCRIPTION
  58. .I ask
  59. writes its arguments one at a time on standard error, and prompts
  60. for a reply.
  61. A response beginning with y or Y selects that argument to be printed
  62. to standard output, anything else rejects it.
  63. .PP
  64. .I ask
  65. is useful for interactively selecting arguments for a command
  66. from a wildcard specification.
  67. .SH OPTIONS
  68. .IP \fB\-s\fP
  69. The argument following is the first part of each prompt.
  70. .SH EXAMPLE
  71. Assume your directory contains the files a b c and d:
  72. .PP
  73. .nf
  74. % cp `ask -s copy *` /dest
  75. copy a? y
  76. copy b?
  77. copy c? y
  78. copy d?
  79. .fi
  80. .sp
  81. The result is that cp a c /dest is executed.
  82. .SH AUTHOR
  83. Ken Yap (University of Rochester)
  84. SHAR_EOF
  85. if test 779 -ne "`wc -c 'ask.1'`"
  86. then
  87.     echo shar: error transmitting "'ask.1'" '(should have been 779 characters)'
  88. fi
  89. echo shar: extracting "'ask.sh'" '(305 characters)'
  90. if test -f 'ask.sh'
  91. then
  92.     echo shar: over-writing existing file "'ask.sh'"
  93. fi
  94. cat << \SHAR_EOF > 'ask.sh'
  95. #!/bin/sh
  96. # ask [ -s string ] args
  97. # prints to stdout those args selected with a [yY]* response from user
  98. case "x$1" in
  99. x-s)    prompt=$2; shift; shift ;;
  100. esac
  101. for i
  102. do
  103.     case "x$prompt" in
  104.     x)    ;;
  105.     *)    1>&2 echo -n "$prompt " ;;
  106.     esac
  107.     1>&2 echo -n "$i? "
  108.     read ans
  109.     case $ans in
  110.     y*|Y*)    echo $i ;;
  111.     esac
  112. done
  113. SHAR_EOF
  114. if test 305 -ne "`wc -c 'ask.sh'`"
  115. then
  116.     echo shar: error transmitting "'ask.sh'" '(should have been 305 characters)'
  117. fi
  118. chmod +x 'ask.sh'
  119. #    End of shell archive
  120. exit 0
  121.